#!/bin/bash
#this script is started from $HOME/.jwmrc

export TEXTDOMAIN=jwm
export OUTPUT_CHARSET=UTF-8

XBEL_PATH=/root/.local/share/recently-used.xbel
MAX_ITEMS=20

tail -n $((MAX_ITEMS*13)) $XBEL_PATH > $HOME/.jwm/tmp/recent_doc_dump

if [[ -e $XBEL_PATH ]];then
   ITEMS=$(sed -rn 's_.*file://([^"]*).*_<Program label="\1">rox -s "\1"</Program>_ p' "$HOME/.jwm/tmp/recent_doc_dump") 
else
   ITEMS="<Program label=\"${XBEL_PATH##*/} $(gettext 'not found')!\"></Program>"
fi
echo '<JWM>'
echo -e "${ITEMS//%/\\x}" | tail -n $MAX_ITEMS
echo '</JWM>'
